Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken rich text blocks in layout picker preview in Firefox #43822

Conversation

andrewserong
Copy link
Member

@andrewserong andrewserong commented Jul 1, 2020

Fix for #43611 where the preview for layouts containing RichText components would fail on the first render, but if you then clicked on other layouts, it would render correctly. This appeared to only affect Firefox, as Chrome looked OK.

In Firefox, when first previewing a layout that contains RichText elements, the blocks would fail rendering when calling createElement in Gutenberg. I'm not 100% sure of the cause, but the issue only occurred when we append the renderedBlocksDOM to the iframe. My suspicion is that because createElement re-uses a single document, creating that document outside of the iFrame context fails when it's added to the iFrame context. Then the subsequent time it's called, perhaps because it's in a fresh context, the subsequent calls work fine.

Whatever the actual cause, swapping out the use of two refs, where we render in the parent context and then appendChild to the iframe, and instead using createPortal to render directly to the iFrame, appears to fix the issue.

Changes proposed in this Pull Request

  • In the start page templates layout picker, remove the renderedBlocksRef and use createPortal to render the <CustomBlockPreview> directly in the iFrame.

Screenshot (before)

image

Screenshot (after)

image

Testing instructions

  • Verify that you can replicate the issue in Add new page - template content doesn't show up in Firefox #43611

  • Sandbox the FSE plugin changes (D45752-code), and your test site

  • In Firefox, go to add a new page in your test site. From the initial "Blank" layout, select a layout that contains RichText components (e.g. paragraphs and headings) — any of the About pages should do it.

  • On first render, the blocks should render correctly and not throw errors (note: many of the layouts do throw unexpected block errors, e.g. Jetpack contact forms / latest posts blocks — these are pre-existing issues and not related to this change)

  • Test across Chrome, Edge, IE, etc to make sure there are no regressions.

Fixes #43611

…ending DOM elements, to resolve failing rich text blocks in Firefox
@matticbot
Copy link
Contributor

@andrewserong andrewserong self-assigned this Jul 1, 2020
@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@andrewserong andrewserong added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Page Layouts [Type] Bug labels Jul 1, 2020
@matticbot
Copy link
Contributor

Caution: This PR affects files in the FSE Plugin on WordPress.com
Please ensure your changes work on WordPress.com before merging.

D45752-code has been created so you can easily test it on your sandbox. See this FieldGuide page about developing in the FSE Plugin for more info: PCYsg-ly5-p2

Copy link
Contributor

@Addison-Stavlo Addison-Stavlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! I think the portal makes more sense.

I tested this on Simple, Atomic, and Atomic sans Gutenberg in both FireFox and Chrome. It fixes the noted issue and I am not noticing any regressions!

@andrewserong andrewserong merged commit e575895 into master Jul 2, 2020
@andrewserong andrewserong deleted the fix/layout-picker-load-rich-text-block-previews-in-firefox branch July 2, 2020 01:19
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new page - template content doesn't show up in Firefox
3 participants